#include "dswlocaltranssvr.h"

CDswlocaltranssvr::CDswlocaltranssvr(LPST_ENV_T pEnv, int nPort)
: CTcpserverbase(pEnv, nPort)
{
	LOG4CPLUS_DEBUG(log_dsw, "Create localtrans server on port " << nPort);
}

CDswlocaltranssvr::~CDswlocaltranssvr()
{
	LOG4CPLUS_DEBUG(log_dsw, "Destroy localtrans server!");
}

void CDswlocaltranssvr::OnAccept(evutil_socket_t fd, struct sockaddr *address, int socklen)
{
	char sKey[64];
	struct sockaddr_in *client = (struct sockaddr_in*)address;
	sprintf(sKey, "%s:%d", inet_ntoa(client->sin_addr), ntohs(client->sin_port));
	CDswlocaltranssession::createNew(m_pEnv, evconnlistener_get_base(m_pListener), fd, sizeof(int), sKey);
}
